home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Red Shark / Missions / Mission_7 / Mission.script < prev    next >
Text File  |  2001-12-24  |  11KB  |  399 lines

  1. //-------------------------------------------------------------------
  2. //
  3. //  This code is copyright 2001 by G5 Software.
  4. //  Any unauthorized usage, either in part or in whole of this code
  5. //  is strictly prohibited. Violators WILL be prosecuted to the
  6. //  maximum extent allowed by law.
  7. //
  8. //-------------------------------------------------------------------
  9.  
  10. class CBreakRingAndConvoyMission extends
  11.   CBaseMission, CBreakRingAndConvoyMissionObjectList, CBreakRingAndConvoyMission_Strings, CNavPointUser
  12. {
  13.   // *** mission constants
  14.  
  15.   final int CONVOY_UNIT_NUM      = 12; // number of units in soviet blocked convoy
  16.   final int CONVOY_KILLED_FAILED = 12; // number of convoy unit to be killed for mission failed
  17.  
  18.   final array CONVOYGROUP_CLASSES   = array( "CSovietTank", "CSovietTank", "CSovietTank");
  19.   final array CONVOYGROUP_AISCRIPTS = array( "CMission7_SovietAttack", "CMission7_SovietAttack", "CMission7_SovietAttack");
  20.   final array CONVOYGROUP_NUM       = array( 4, 4, 4);
  21.  
  22.  
  23.   // *** mission creation
  24.  
  25.   int GetAutoGeneratedUnitsQty()
  26.   {
  27.     return
  28.       CONVOY_UNIT_NUM            // additional units generated automatically
  29.     + 6                          // additional units generated automatically
  30.     + 2 + 1 + 2 + 1 + 2 + 1 + 2  // additional units generated automatically
  31.     + 3                          // additional units generated automatically
  32.     + 6;                         // global components generated in constructor
  33.   }
  34.  
  35.   void CBreakRingAndConvoyMission()
  36.   {
  37.     BaseMission_InitMission();
  38.  
  39.     BaseMission_UpdateLoadProgress();
  40.     CreateComponent("DebugCamera", "GameObject", "CDebugCamera");
  41.     SetComponentPosition("DebugCamera",
  42.       matrix(
  43.         1.0, 0.0, 0.0, 8500.0,
  44.         0.0, 1.0, 0.0, 10300.0,
  45.         0.0, 0.0, 1.0,  600.0,
  46.         0.0, 0.0, 0.0,    1.0
  47.       ));
  48.  
  49.     // CreateComponent(IDToRegister, ComponentID, ScriptName | FileName | "")
  50.     BaseMission_UpdateLoadProgress();
  51.     CreateComponent("Atmosphere", "Atmosphere", "CBreakRingAndConvoyMission_Atmosphere");
  52.  
  53.     BaseMission_UpdateLoadProgress();
  54.     CreateComponent("Sky", "SkyObject", "CBreakRingAndConvoyMission_Sky");
  55.  
  56.     BaseMission_UpdateLoadProgress();
  57.     CreateComponent("Terrain", "ProgressiveTerrainObject", "CBreakRingAndConvoyMission_Terrain");
  58.  
  59.     BaseMission_UpdateLoadProgress();
  60.     CreateComponent("Forest", "Forest", "CBreakRingAndConvoyMission_Forest");
  61.  
  62.     BaseMission_UpdateLoadProgress();
  63.     CreateComponent("AIController", "AIController", "CMission7_AIController");
  64.  
  65.     BaseMission_CreateObjects();
  66.  
  67.  
  68.     // --- create Soviet army
  69.  
  70.     /*
  71.     CreateUnitLine(
  72.       "SovietTank_",
  73.       "CSovietTank",
  74.       "CMission7_SovietAttack",
  75.       CONVOY_UNIT_NUM,
  76.       9131.0, 10326.0,
  77.       9834.0, 10330.0);
  78.     */
  79.  
  80.     CreateUnitLineGroup(
  81.       "SovietConvoy_",
  82.       CONVOYGROUP_CLASSES,
  83.       CONVOYGROUP_AISCRIPTS,
  84.       CONVOYGROUP_NUM,
  85.       CONVOY_UNIT_NUM,
  86.       9131.0, 10326.0,
  87.       9834.0, 10330.0);
  88.  
  89.  
  90.     // --- create Nazi army
  91.  
  92.     // group A
  93.     CreateUnitLine(
  94.       "NaziTank_A_",
  95.       "CGermanTank",
  96.       "CMission7_NaziAttack",
  97.       6,//10,
  98.       GetNavPoint("NavPoint_Encirclement_A"),
  99.       GetNavPoint("NavPoint_Encirclement_B"));
  100.  
  101.     // group B
  102.     CreateUnitLine(
  103.       "NaziTank_B_",
  104.       "CGermanTank",
  105.       "CMission7_NaziAttack",
  106.       2,//3,
  107.       GetNavPoint("NavPoint_Encirclement_B"),
  108.       GetNavPoint("NavPoint_Encirclement_C"));
  109.  
  110.     // group C
  111.     CreateUnitLine(
  112.       "NaziTank_C_",
  113.       "CGermanTank",
  114.       "CMission7_NaziAttack",
  115.       1,//3,
  116.       GetNavPoint("NavPoint_Encirclement_C"),
  117.       GetNavPoint("NavPoint_Encirclement_D"));
  118.  
  119.     // group D
  120.     CreateUnitLine(
  121.       "NaziTank_D_",
  122.       "CGermanTank",
  123.       "CMission7_NaziAttack",
  124.       2,//3,
  125.       GetNavPoint("NavPoint_Encirclement_D"),
  126.       GetNavPoint("NavPoint_Encirclement_E"));
  127.  
  128.     // group E
  129.     CreateUnitLine(
  130.       "NaziTank_E_",
  131.       "CGermanTank",
  132.       "CMission7_NaziAttack",
  133.       1,//3,
  134.       GetNavPoint("NavPoint_Encirclement_E"),
  135.       GetNavPoint("NavPoint_Encirclement_F"));
  136.  
  137.     // group F
  138.     CreateUnitLine(
  139.       "NaziTank_F_",
  140.       "CGermanTank",
  141.       "CMission7_NaziAttack",
  142.       2,//3,
  143.       GetNavPoint("NavPoint_Encirclement_F"),
  144.       GetNavPoint("NavPoint_Encirclement_G"));
  145.  
  146.     // group G
  147.     CreateUnitLine(
  148.       "NaziTank_G_",
  149.       "CGermanTank",
  150.       "CMission7_NaziAttack",
  151.       1,//3,
  152.       GetNavPoint("NavPoint_Encirclement_G"),
  153.       GetNavPoint("NavPoint_Encirclement_H"));
  154.  
  155.     // group H
  156.     CreateUnitLine(
  157.       "NaziTank_H_",
  158.       "CGermanTank",
  159.       "CMission7_NaziAttack",
  160.       2,//6,
  161.       GetNavPoint("NavPoint_Encirclement_H"),
  162.       GetNavPoint("NavPoint_Encirclement_I"));
  163.  
  164.     // group I
  165.     CreateUnitLine(
  166.       "NaziTank_I_",
  167.       "CGermanTank",
  168.       "CMission7_NaziAttack",
  169.       2,//3,
  170.       GetNavPoint("NavPoint_Encirclement_I"),
  171.       GetNavPoint("NavPoint_Encirclement_A"));
  172.   }
  173.  
  174.  
  175.   // *** routine functions
  176.  
  177.   void CreateUnitLine(
  178.     string  _NamePrefix,
  179.     string  _ObjectScript,
  180.     string  _AIScript,
  181.     int     _ObjectNum,
  182.     float   _LineStartX,
  183.     float   _LineStartY,
  184.     float   _LineEndX,
  185.     float   _LineEndY)
  186.   {
  187.     for ( int u = 0; u < _ObjectNum; u = u + 1)
  188.     {
  189.       float x = _LineStartX + (_LineEndX - _LineStartX) * u / _ObjectNum;
  190.       float y = _LineStartY + (_LineEndY - _LineStartY) * u / _ObjectNum;
  191.  
  192.       BaseMission_UpdateLoadProgress();
  193.       CreateComponent( _NamePrefix + u, "GameObject", _ObjectScript);
  194.  
  195.       SetComponentPosition(
  196.         _NamePrefix + u,
  197.         matrix(
  198.           1.0, 0.0, 0.0, x,
  199.           0.0, 1.0, 0.0, y,
  200.           0.0, 0.0, 1.0, 0.0,
  201.           0.0, 0.0, 0.0, 1.0));
  202.  
  203.       SetBehaviorTask( _NamePrefix + u, _AIScript);
  204.     }
  205.   }
  206.  
  207.  
  208.   void CreateUnitLineGroup(
  209.     string  _NamePrefix,
  210.     array   _GroupObjectScript,
  211.     array   _GroupAIScript,
  212.     array   _GroupObjectNum,
  213.     int     _ObjectNum,
  214.     float   _LineStartX,
  215.     float   _LineStartY,
  216.     float   _LineEndX,
  217.     float   _LineEndY)
  218.   {
  219.     int GroupIndex = 0;
  220.     int InGroupIndex = 0;
  221.  
  222.     for ( int u = 0; u < _ObjectNum; u = u + 1)
  223.     {
  224.       float x = _LineStartX + (_LineEndX - _LineStartX) * u / _ObjectNum;
  225.       float y = _LineStartY + (_LineEndY - _LineStartY) * u / _ObjectNum;
  226.  
  227.       BaseMission_UpdateLoadProgress();
  228.       CreateComponent( _NamePrefix + u, "GameObject", _GroupObjectScript[GroupIndex]);
  229.  
  230.       SetComponentPosition(
  231.         _NamePrefix + u,
  232.         matrix(
  233.           1.0, 0.0, 0.0, x,
  234.           0.0, 1.0, 0.0, y,
  235.           0.0, 0.0, 1.0, 0.0,
  236.           0.0, 0.0, 0.0, 1.0));
  237.  
  238.       SetBehaviorTask( _NamePrefix + u, _GroupAIScript[GroupIndex]);
  239.  
  240.       InGroupIndex = InGroupIndex + 1;
  241.       if ( InGroupIndex >= int(_GroupObjectNum[GroupIndex]))
  242.       {
  243.         GroupIndex = GroupIndex + 1;
  244.         InGroupIndex = 0;
  245.       };
  246.     }
  247.   }
  248.  
  249.   array m_MissionObjectivesStatuses =
  250.           array(
  251.             str_ObjectiveInProgress,
  252.             str_ObjectiveInProgress
  253.           );
  254.  
  255.   array m_BonusMissionObjectivesStatuses =
  256.           array(
  257.           );
  258.  
  259.   //
  260.   //  Mission statistics
  261.  
  262.   string GetMissionStatistics()
  263.   {
  264.     return str_StatisticsTitle + NaziKilled;
  265.   }
  266.  
  267.   //
  268.   //  Mission navpoints
  269.  
  270.   array GetNavPoints()
  271.   {
  272.     array navpoints =
  273.       array(
  274.         GetNavPoint("NavPoint_Encirclement"),
  275.         GetNavPoint("NavPoint_Pagubino")
  276. //        vector(8600, 8170, 589),
  277. //        vector(12200, 4706, 428.0)
  278.       );
  279.     return navpoints;
  280.   }
  281.  
  282.   //
  283.   //  Mission map skin file
  284.  
  285.   string GetMapSkinFileName()
  286.   {
  287.     return "Missions/Mission_7/Map.skin";
  288.   }
  289.  
  290.  
  291.   //
  292.   //  Objective constants and variables
  293.   //
  294.  
  295.   final int  KILL_GROUP_A_TO_BREACH = 5; // number of nazi units in group A that should be killed to start soviet breach
  296.   final int  KILL_GROUP_O_TO_COMPLETE = 7; // number of nazi units in group O that should be killed to complete mission
  297.  
  298.   int  m_NaziGroup_A_Killed = 0;
  299.   int  m_NaziGroup_O_Killed = 0;
  300.  
  301.   //
  302.   //  Object destroyed event handler
  303.   //
  304.  
  305.   //#TMP:
  306.   int NaziKilled = 0;
  307.   int SovietKilled = 0;
  308.   boolean GroupA_Broken = false;
  309.  
  310.   void OnGameObjectDestroyed(string _id)
  311.   {
  312.     BaseMission_OnGameObjectDestroyed(_id);
  313.  
  314.     if ( (!GroupA_Broken) && Core_IsStringStartsWith(_id, "NaziTank_A_"))
  315.     {
  316.       m_NaziGroup_A_Killed = m_NaziGroup_A_Killed + 1;
  317.  
  318.       string message = str_BlockingTankDestrMsg_1 +
  319.                        m_NaziGroup_A_Killed +
  320.                        str_BlockingTankDestrMsg_2;
  321.  
  322.       Core_BroadcastEvent(
  323.         "OnDisplayMessage",
  324.         message,
  325.         m_GoodNewsColor
  326.       );
  327.  
  328.       if ( m_NaziGroup_A_Killed >= KILL_GROUP_A_TO_BREACH)
  329.       {
  330.         BaseMission_CompleteObjective(0);
  331.         Core_BroadcastEvent( "OnGroupABroken");
  332.         GroupA_Broken = true;
  333.         Core_SendEventTo(
  334.             "Helicopter",
  335.             "ShowEventPoint",
  336.             vector(9278.0, 10326.0, 370.0), //        - point to show
  337.             80.0                           //        - distance from camera to point
  338.         );
  339.       }
  340.     }
  341.  
  342.     if (Core_IsStringStartsWith(_id, "Nazi"))
  343.     {
  344.       NaziKilled = NaziKilled + 1;
  345.     }
  346.  
  347.     if ( Core_IsStringStartsWith(_id, "Nazi_Ambush_O"))
  348.     {
  349.       m_NaziGroup_O_Killed = m_NaziGroup_O_Killed + 1;
  350.  
  351.       if ( m_NaziGroup_O_Killed >= KILL_GROUP_O_TO_COMPLETE)
  352.       {
  353.         BaseMission_CompleteObjective(1);
  354.         Core_BroadcastEvent("OnConvoyContinue");
  355.       }
  356.     }
  357.  
  358.     if (Core_IsStringStartsWith(_id, "SovietConvoy_"))
  359.     {
  360.       SovietKilled = SovietKilled + 1;
  361.  
  362.       string message = str_ConvoyDestroyedMsg_1 +
  363.                        (CONVOY_UNIT_NUM - SovietKilled) +
  364.                        str_ConvoyDestroyedMsg_2;
  365.  
  366.       Core_BroadcastEvent(
  367.         "OnDisplayMessage",
  368.         message,
  369.         m_BadNewsColor
  370.       );
  371.      Core_SendEventTo(
  372.         "Helicopter",
  373.         "ShowEventObject",
  374.         _id,                       //     - id of object to show
  375.         80.0                      //     - distance from camera to object
  376.         );
  377.  
  378.       if ( SovietKilled >= CONVOY_KILLED_FAILED)
  379.       {
  380.         Core_BroadcastEvent(
  381.           "OnDisplayMessage",
  382.           str_MissionFailedMsg,
  383.           m_BadNewsColor
  384.         );
  385.  
  386.         BaseMission_DelayedQuit();
  387.       }
  388.     }
  389.   }
  390.  
  391.   void OnMissionLoaded()
  392.   {
  393.     Core_SendEventTo("Helicopter", "OnInitiallyEnableTargetScreen", false);
  394.  
  395.     // Start mission music playing
  396.     Core_SendEventTo(SOID_MusicController, "PlayMissionMusic", 7);
  397.   }
  398. }
  399.